<?php

namespace app\model\training;

use app\BaseModel;
use app\model\UserModel;
use think\model\relation\BelongsTo;
use think\model\relation\HasMany;

/**
 * 培训讲座-任务
 */
class TrainingTaskModel extends BaseModel
{
    protected $name = 'training_task';

    /**
     * 用户
     * @return BelongsTo
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(UserModel::class,'uid')->bind([
            'user_name' => 'name',
            'role_name'
        ]);
    }

    /**
     * 讲师
     * @return BelongsTo
     */
    public function TrainingLecturer(): BelongsTo
    {
        return $this->belongsTo(TrainingLecturerModel::class,'lecturer_id')->bind([
            'lecturer_name' => 'name',
            'lecturer_sex' => 'sex',
            'lecturer_age' => 'age',
            'lecturer_photo' => 'photo',
            'lecturer_introduce' => 'introduce',
            'lecturer_label' => 'label',
        ]);
    }

    /**
     * 讲座类型
     * @return BelongsTo
     */
    public function typeName(): BelongsTo
    {
        return $this->belongsTo(TrainingTypeModel::class,'type_id')->bind([
            'type_name' => 'name'
        ]);
    }

    /**
     * 教材
     * @return BelongsTo
     */
    public function textbook(): BelongsTo
    {
        return $this->belongsTo(TrainingTextbookModel::class,'textbook_id')->bind([
            'textbook_name' => 'name',
            'textbook_cover' => 'cover',
            'textbook_file' => 'file',
            'textbook_pdf' => 'pdf',
            'textbook_type_name',
        ]);
    }

    /**
     * 任务部门
     * @return HasMany
     */
    public function TrainingTaskDepartment(): HasMany
    {
        return $this->hasMany(TrainingTaskDepartmentModel::class,'task_id');
    }

    /**
     * 任务量表-前
     * @return HasMany
     */
    public function TrainingTaskRatingScaleFront(): HasMany
    {
        return $this->hasMany(TrainingTaskRatingScaleModel::class,'task_id')->where('type','=',1);
    }

    /**
     * 任务量表-后
     * @return HasMany
     */
    public function TrainingTaskRatingScaleAfter(): HasMany
    {
        return $this->hasMany(TrainingTaskRatingScaleModel::class,'task_id')->where('type','=',2);
    }
}